package com.chensf.studydemo.guide

import android.content.Intent
import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.chensf.studydemo.R
import com.chensf.studydemo.guide.animation.AnimationGuideActivity
import com.chensf.studydemo.guide.design.DesignGuideActivity
import kotlinx.android.synthetic.main.activity_main.*

class DevGuideActivity : AppCompatActivity(){
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        recyclerView.adapter = object : RecyclerView.Adapter<MyViewHolder>() {
            override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
                return MyViewHolder(
                    layoutInflater.inflate(
                        R.layout.view_simple_list_item,
                        parent,false
                    )
                )
            }

            override fun getItemCount(): Int {
                return resources.getStringArray(R.array.dev_guide_level_dir).size
            }

            override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
                (holder.itemView as TextView).text =
                    resources.getStringArray(R.array.dev_guide_level_dir)[position]
                holder.itemView.setOnClickListener {
                    when (position) {
                        0 -> startActivity(
                            Intent(
                                this@DevGuideActivity,
                                AnimationGuideActivity::class.java
                            )
                        )
                        1 ->  startActivity(
                            Intent(
                                this@DevGuideActivity,
                                DesignGuideActivity::class.java
                            )
                        )
                        2 ->  startActivity(
                            Intent(
                                this@DevGuideActivity,
                                SystemScheduleDemo::class.java
                            )
                        )
                        else
                        -> startActivity(
                            Intent(
                                this@DevGuideActivity,
                                AnimationGuideActivity::class.java
                            )
                        )
                    }
                }
            }
        }
        recyclerView.layoutManager = LinearLayoutManager(this)
    }

    class MyViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView)
}